package com.example.module_home.presenter

import com.example.module_common.base.BaseModel
import com.example.module_common.base.BaseObserver
import com.example.module_common.base.BasePresenter
import com.example.module_common.model.ArticleListModel
import com.example.module_common.model.BannerModel
import com.example.module_home.view.HomeView

class HomePresenter (homeView: HomeView):BasePresenter<HomeView>(homeView) {

    /**
     * 首页广告
     */
     fun banner() {
        addDisposable(apiServer.banner(), object : BaseObserver<BaseModel<List<BannerModel>>>(baseView) {

            override fun onSuccess(o: BaseModel<List<BannerModel>>) {
                baseView.onLoadBanner(o.data!!)
            }



            override fun onError(msg: String?) {
                baseView.showError(msg!!)
            }
        })
    }

     fun artList(page:Int){
        addDisposable(apiServer.articleList(page), object : BaseObserver<BaseModel<List<ArticleListModel>>>(baseView) {

            override fun onSuccess(o: BaseModel<List<ArticleListModel>>) {
                baseView.onLoadArticleList(o.data!!)
            }



            override fun onError(msg: String?) {
                baseView.showError(msg!!)
            }
        })
    }
}